<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ include file="/pages/inc/taglibs.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>开通工具服务</title>
	<%@ include file="/pages/inc/header.jsp" %>
	<style>
	#ptstool{color:blue}
	</style>
</head>

<body>
<%@ include file="/pages/inc/common.jsp" %>
<%@ include file="/pages/inc/menu.jsp" %>

<div class="pts-main">
	<%@ include file="/pages/inc/nav_pm.jsp" %>
	<div class="pts-page-title"><span>使用代码质量分析工具服务</span></div>
	<div class="container-fluid">
		<input type="button" value="开始使用" onclick="javascript:showStatus()">
		<input type="button" onclick="javascript:history.back()" value="返回工具服务首页">
		<br>注：点击“开始使用”按钮后：退回到PTS工具服务页面，系统自动新增一条服务使用记录。
	</div>
	<div class="pts-page-title"><span>选择需要分析的代码包</span></div>
	<div class="container-fluid">
		<form id="sonarserviceForm" class="pts-form" enctype="multipart/form-data" method="post" action="<c:url value='/codePackages/save?from=tool'/>">
			<input id="serviceId" name="serviceId" type="hidden"  value="<c:out value='${serviceId}'/>"/>
			<input id="codePackagesID" name="codePackagesID" type="hidden" value="" />
			<input id="projectId" name="projectId" type="hidden" value="<c:out value='${projectId}'/>">
			<input id="projectName" name="projectName" type="hidden" value="" />
			<input id="serviceName" name="serviceName" type="hidden" value="" />
			<input id="status" name="status" type="hidden" value="0" />
			<div class="pts-row" > 
				<div class="pts-cell">
					<fmt:message key="codePackages.form.packagename"/>：
					<input id="packageFile" name="packageFile" type="file" />* 请选择代码包
				</div>
				<div class="pts-cell">
					<fmt:message key="codePackages.form.packageversion"/>：
					<input id="packageversion" name="packageversion" type="text" class="text" style="width:40px;"/>
				</div>
			</div>
			<div class="pts-row" > 
				<div class="pts-cell">
					Sources：
					<input id="sources" name="sources" type="text" value="src" class="text" style="width:200px;"/>
				</div>
				<div class="pts-cell">
					Binaries：
					<input id="binaries" name="binaries" type="text" value="WebApp/WEB-INF/classes" class="text" style="width:200px;"/>
				</div>
			</div>
			<div class="pts-row" > 
				<div class="pts-cell">
					Language：
					<input id="language" name="language" type="text" value="java" class="text" style="width:40px;"/>
				</div>
				<div class="pts-cell">
					Description：
					<input id="description" name="description" type="text" value="这是一个代码包" class="text" style="width:200px;"/>
				</div>	
			</div>
			<div class="pts-row" > 
				<div class="pts-cell">
					<input id="submit_button" class="button" type="submit" value="上传">
				</div>
			</div>
		</form>
		<br>
		<div id="code-pacakges"></div> 
	</div>
</div>

<%@ include file="/pages/inc/footer.jsp" %>
<script type="text/javascript">
	//====================================================================
	//定义模块类实例名（taskModule）、页面全局变量名（projectServiceVar）
	var projectServiceVar;
	var codePackageId="";
	
	//====================================================================
	
	//页面配置方法
	//author：robin
	//
	function initConfig(){
		//页面变量
		projectServiceVar = {
			//*******************************常量区******************************************//
			TASK_ZY:1,//属性说明1
			TASK_XS:"常量",//属性说明2
			//*******************************变量区******************************************//
		};
	}
	function showStatus(){
		var serviceId = $("#serviceId").val();
		if(codePackageId == "")
			alert("请选择需要质量分析的代码包！");
		else
		    window.location="<c:url value='/sonarservices/useToolService'/>?codePackageId="+codePackageId+"&serviceId="+serviceId;
	}
	function fmtCodePackageList(orders){
		 var html="<table class='pts-table'>";
		 html+="<tr>"+
			 "<th>编号</th> "+
			 "<th>包文件名</th>"+
			 "<th>包版本</th>"+
			 "<th>包大小</th>"+
			 "<th>源码</th>"+
			 "<th>二进制文件</th>"+
			 "<th>语言</th>"+
			 "<th>上传时间</th>"+ 
			 "<th>上传人 </th> "+
			 "<th>操</th> "+
			 "<th>作</th> "+
			 "</tr>";
		 //循环输出订单信息 
		 var serviceOptdel = "";
		 var serviceOptuse = "";
		 var rows = orders.rows;
		 for(var i=0;i<rows.length;i++){
		  	   html+="<tr id='package-"+rows[i].id+"' class='cp'>";
		  	   html+="	<td>"+(i+1) +"</td>";
		  	   html+="	<td>"+rows[i].packagename+" </td>";
		  	   html+="	<td>"+rows[i].packageversion+" </td>";
		  	 	html+="	<td>"+rows[i].packagesize+" </td>";
		  		html+="	<td>"+rows[i].sources+" </td>";
		  		html+="	<td>"+rows[i].binaries+" </td>";
		  		html+="	<td>"+rows[i].language+" </td>";
		  	   html+="	<td>"+rows[i].createtime+"</td>";
		  	   html+="	<td>"+rows[i].creator+"</td>";
		  	   serviceOptdel = "<a href='javascript:void(0)' onclick='deleteOne(\""+rows[i].id+"\")'>删除</a>";
		  	   serviceOptuse = "<a href='javascript:void(0)' onclick='selectOne(\""+rows[i].id+"\")'>使用</a>";
		  	   html+="	<td>"+serviceOptdel+"</td>";
		  	   html+="	<td>"+serviceOptuse+"</td>";
		  	   html+="</tr>";
		 }
		 html+="</table>";
		 return html;
	}
	//删除一个包
	function deleteOne(id){
		$.ajax({
			url: contextPath+"/codePackages/delete/"+id,
			cache:false,
			async:false,
			success: function(data, textStatus, jqXHR){
				initCodepackages();//初始化服务模块
			}
		});
	}
	//使用选中的包
	function selectOne(id){
		$(".cp").each(function(i,val){
			$(val).css("background-color","white");
		});
		$("#package-"+id).css("background-color","yellow");
		codePackageId=id;
	}
	//初始化任务信息
	//author：JCJ
	function initCodepackages() {
		var projectId = $("#projectId").val();
		$.ajax({
			url: contextPath+"/codePackages/listCodePackages",
			type:"POST",
			data:{"projectId":projectId},
			cache:false,
			async:false,
			success: function(data, textStatus, jqXHR){
				if(data){
					$("#code-pacakges").html(fmtCodePackageList(data));
				}
			}
		});
	}
	
	//====================================================================
	//主方法
	$(function() {
		initConfig();//初始化页面配置
		initCodepackages();//初始化服务模块
	});
</script>
</body>
</html>
